<?php
require 'config.php';
require 'theme.php';

if (!file_exists(DATA_FOLDER)) {
	theme('error', '<p>'.__("Error: File not found.") . '</p>');
}

if (isset($_POST['submit'])) {
	if (isset($_POST["unlink"])) {  
		while (list($key, $value) = each($_POST["unlink"])) {
			if (file_exists(DATA_FOLDER . $value)) {
				unlink(DATA_FOLDER . $value);
			}
		}
	}
}
?>
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<title>Twitter Backup - Download</title>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8">
<link href="tbackup.css" rel="stylesheet" type="text/css">
</head>

<script type="text/javascript" language="javascript">
function onCheckAll() {
    var _checkboxs = document.getElementsByName("unlink[]");
    for(var i = 0 ;i < _checkboxs.length; i++) {
		_checkboxs[i].checked = true;
	}
}
</script>

<body>
<h2>Twitter Backup - Download</h2>
<div style="border-top:2px dashed #cccccc;height: 1px;overflow:hidden;width:550px"></div>
<?php if ($_GET['msg']) echo '<p>' . $_GET['msg'] . '</p>'; ?>
<?php if ($_GET['frompage']) {
echo '<p>From page ' . $_GET['frompage'] . ' to page ' . $_GET['topage'] . '</p>';
echo '<div style="border-top:2px dashed #cccccc;height: 1px;overflow:hidden;width:550px"></div>';
} ?>
<form method="post">
<?php
$files = scandir(DATA_FOLDER);
foreach($files as $file) {
	if ($file != '.' && $file != '..') {
		echo '<input name="unlink[]" type="checkbox" value="' . $file . '"><a href=\'' . DATA_FOLDER . $file . '\'>' .  $file . '</a><br>';
	}
}
?>
<input name="submit" type="submit" value="Remove" />
<input name="selectAll" type="button" id="selectAll" value="Select All" onClick="onCheckAll()">
</form>
<div style="border-top:2px dashed #cccccc;height: 1px;overflow:hidden;width:550px"></div>
<p>Follow me on Twitter: <a href="http://twitter.com/lordong" target="_blank">@lordong</a></p>
<p>My Blog: <a href="http://lordong.net" target="_blank">LorDong's Blog</a></p>
<p>Source Code: <a href="http://code.google.com/p/tbackup" target="_blank">http://code.google.com/p/tbackup</a></p>
<a href='index.php'>Home</a>
</body>
</html>
